﻿Public Class Login

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Try
            Dim pwd As String = ChangePassword.EncodePwd(Me.TextBox1.Text.Trim())
            If String.Compare(pwd, My.MySettings.Default.Password) = 0 Then
                Me.DialogResult = DialogResult.OK
                Me.Close()
            Else
                Throw New InvalidOperationException("Invalid Password.")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End Try
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim pwd As String = Me.TextBox1.Text.Trim()
        Me.BtnOK.Enabled = pwd.Length > 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim c As New ChangePassword()
        Me.DialogResult = c.ShowDialog()
        Me.Close()
    End Sub
End Class